﻿using System;

namespace RG.Common.Misc
{
    public static class TraceError_Ext
    {
        public static void TraceError(this log4net.ILog log, Exception ex, string note)
        {
            for (; ex != null; ex = ex.InnerException)
            {
                log.ErrorFormat("{0}: {1}, {2}", note, ex.GetType(), ex.Message);
                log.ErrorFormat("Stack Trace: {0}", ex.StackTrace);
                note = "InnerException";
            }
        }

        public static string TraceError(this Exception ex, string note)
        {
            string res = string.Empty;
            for (; ex != null; ex = ex.InnerException)
            {
                res = string.Format(
                    "{0}Исключение {1} при {2}: {3}\r\n" +
                    "StackTrace: {4}\r\n",
                    res, ex.GetType(), note, ex.Message, ex.StackTrace);
                note = "InnerException";
            }
            return res;
        }
    }
}
